package student.action;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import edu.student.models.*;

public class MyProfile extends ActionSupport {

	/**
	Author: Satya Deepthi Bhagi
	 **/
	
	private static final long serialVersionUID = 1L;
	private String username="";
	private List<News> news;
	private List<Announcements> announcements;
	private String image="";
	private Timestamp lastLogin;
	private String userid="";
	
	

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public List<Announcements> getAnnouncements() {
			return announcements;
		}

		public void setAnnouncements(List<Announcements> announcements) {
			this.announcements = announcements;
		}

		public List<News> getNews() {
			return news;
		}

		public void setNews(List<News> news) {
			this.news = news;
		}
		public String getUsername() {
			return username;
		}

		public void setUsername(String username) {
			this.username = username;
		}
		

		public String getImage() {
			return image;
		}

		public void setImage(String image) {
			this.image = image;
		}
		
		public Timestamp getLastLogin() {
			return lastLogin;
		}

		public void setLastLogin(Timestamp lastLogin) {
			this.lastLogin = lastLogin;
		}
   User user = new User();
   User friend = new User();
	public String execute() throws Exception {
		Map<String, Object> session = ActionContext.getContext().getSession();
		User user = (User) session.get("user");
		if (user == null) {
			user = new User();
		}
		userid=user.getRollNor();
		username=user.getUsername();
		image=user.getImage();
		lastLogin=user.getLastLogin();
		System.out.println("Session User Roll Nor is"+ user.getRollNor());
		friend = User.findone("select * from user where roll_no = '" + userid+"'");
		friend.setInterests(Interest.getInterests(" where u.roll_no='"+userid+"' "));
		news = News.getNews(" where ui.roll_No='"+user.getRollNor()+"' ");
		announcements=Announcements.getAnnouncements(" where ui.roll_No='"+user.getRollNor()+"' ");
		return "success";
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public User getFriend() {
		return friend;
	}

	public void setFriend(User friend) {
		this.friend = friend;
	}

	
	
}
